package dac.sort.test;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;


public class ArrayGen {

	public void genArray(String fileName){
		File file = new File(fileName);
		FileWriter fw = null;
		try {
			fw = new FileWriter(file);
			
			String str = getRandomString();
			fw.append(str);
			fw.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if(fw != null)
					fw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	private String getRandomString(){
		StringBuffer buffer = new StringBuffer();
		Random random = new Random();
		for (int i = 0; i < 5000; i++) {
			if(buffer.length() == 0){
				buffer.append(random.nextInt(50000));
			} else {
				buffer.append(",").append(random.nextInt(50000));
			}
		}
		return buffer.toString();
	}
	
	public static void main(String[] args) {
		ArrayGen gen = new ArrayGen();
		gen.genArray("D:\\workspace\\sort\\src\\array1.txt");
	}
}
